package com.tianluo.tianluobookstore.enums;

public enum OrderStatus {

    PENDING("PENDING", "待处理"),

    WAIT_SENDING("WAIT_SENDING", "待发货"),

    SEND_ED("SEND_ED", "已发货"),

    RECEIVED("RECEIVED", "已收货"),

    COMPLETED("COMPLETED", "已完成"),

    CANCELLED("CANCELLED", "已取消"),;

    // 你可以在这里添加更多的状态
    // 例如：
    // CANCELLED("CANCELLED", "已取消"),
    // PROCESSING("PROCESSING", "处理中"),
    // DELIVERED("DELIVERED", "已配送"),
    // ON_HOLD("ON_HOLD", "暂停"),
    // 等

    private final String code;
    private final String description;

    OrderStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取对应的枚举实例
     *
     * @param code 枚举代码
     * @return 对应的枚举实例，如果不存在则返回null
     */
    public static OrderStatus fromCode(String code) {
        for (OrderStatus status : OrderStatus.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }
}
